import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Shop } from './entities/shop.entity';

@Injectable()
export class ShopsService {
  constructor(
    @InjectRepository(Shop)
    private shopsRepository: Repository<Shop>,
  ) {}

  findAll() {
    return this.shopsRepository.find();
  }

  findOne(id: number) {
    return this.shopsRepository.findOne({ where: { id } });
  }

  async createShop(shopData: Partial<Shop>): Promise<Shop> {
    const shop = this.shopsRepository.create(shopData);
    return this.shopsRepository.save(shop);
  }

  async updateShop(id: number, shopData: Partial<Shop>): Promise<Shop> {
    await this.shopsRepository.update(id, shopData);
    return this.findOne(id);
  }

  async deleteShop(id: number): Promise<void> {
    await this.shopsRepository.delete(id);
  }
}
